<!--  -->
<template>
    <div style="padding-bottom: 42px">
        <van-form>
            <div class="font15 mt10">
                <div class="pl10">
                    <span class="titletext ">项目复杂度计算</span>
                </div>
                <div class="bcolor-e" style="height: 2px;"></div>
            </div>
            <section-header sectionTitle="IT交付复杂度分值测算表"></section-header>
              <el-table :data="listData" :header-cell-style="{ textAlign: 'center' }" :cell-style="{ textAlign: 'center' }" border
                        style="width: 100%" @selection-change="handleSelectionChange" ref="multipleTable" tooltip-effect="dark">
                <el-table-column prop="model" label="IT模式" width="90" />
                <el-table-column prop="type" label="分类" width="140" />
                <el-table-column prop="infos" label="详述" width="150" />
                <el-table-column prop="typetomodel" label="对应自主实施类型" width="120" />
                <el-table-column
                    type="selection"
                    width="60"
                    label="选择">
                </el-table-column>
                <el-table-column prop="number" label="分值" width="60" />
              </el-table>
            <div class="footer">
              <van-button block type="info" native-type="submit" @click="onSubmit"
                          style="display: inline-block; width: 100%; border: 0px solid #60a9ec">确定</van-button>
            </div>
        </van-form>
    </div>
</template>


<script>

import { mapGetters } from "vuex";
import {  Notify } from "vant";
export default {
    data() {
        return {

            params: this.$route.query,
            listData: [{
              "model":"设备",
              "type":"购销",
              "infos":"标准化软件硬件采购购销，如:无线覆盖（AP）、网络设备、视频会议设备、显示屏、电脑等。",
              "typetomodel":"/",
              "number":"1",
            },{
              "model":"自主项目",
              "type":"硬件研发",
              "infos":"基于行业业务场景的硬件研发，为客户提供定制化硬件产品类的自主研发项目，如:5G摄像头、5G感知设备、5G单兵设备、智能硬件集成、人脸识别设备等。",
              "typetomodel":"自主开发",
              "number":"5",
            },{
              "model":"自主项目",
              "type":"软件、系统平台开发服务",
              "infos":"基于行业业务系统的软件研发，为客户提供定制化业务平台类的自主研发项目，如:XX办公平台、XX管理平台、XX系统、XXPaaS平台、XX云管理平台、XX大数据平台等。",
              "typetomodel":"自主开发",
              "number":"4",
            },{
              "model":"自主项目",
              "type":"软件集成",
              "infos":"为客户提供软件平台的集成项目，包含制定标准化接口，将客户系统间业务、数据打通调试、软件升级等软件集成工作（含成熟软件部署），如:XX门户集成、XX平台集成、XX系统集成、XX业务流程集成、XX应用集成等。",
              "typetomodel":"自主集成",
              "number":"3",
            },{
              "model":"自主项目",
              "type":"硬件集成",
              "infos":"为客户提供IT设施类的集成项目，包含标准化硬件安装调试等集成服务工作，如:数通设备类、无线覆盖类、网络安全类、视频会议类、视频监控类、综合布线、升级割接搬迁、机房改造类等。",
              "typetomodel":"自主集成",
              "number":"2",
            },{
              "model":"自主项目",
              "type":"运维服务",
              "infos":"为客户提供设备、业务系统运维服务工作。",
              "typetomodel":"自主服务",
              "number":"1",
            },{
              "model":"自主项目",
              "type":"等保测评、咨询类、外部认证服务",
              "infos":"为客户提供测评、咨询、认证等服务。",
              "typetomodel":"自主服务",
              "number":"2",
            },{
              "model":"自主项目",
              "type":"全流程集成管理",
              "infos":"由自有项目交付经理主导项目端到端管理，牵头全流程交付实施过程，如需求管理、进度管理、质量管理、沟通管理等",
              "typetomodel":"自主管理",
              "number":"1",
            },{
              "model":"自主项目",
              "type":"融自有产品标签",
              "infos":"包括“三化”方案、高价值应用、9one平台、原子能力、安全能力等",
              "typetomodel":"自主应用",
              "number":"0",
            },{
              "model":"非自主项目",
              "type":"关键环节管控类项目",
              "infos":"牵头对项目投标签约、开工启动、验收交维等关键环节开展项目管理，其他全流程交付实施过程由第三方产品厂商或集成商完成与客户对接交付的项目",
              "typetomodel":"非自主项目",
              "number":"0.5",
            }],
          multipleSelection: [],
          multipleTable:[],
          itOrder:''
        };
    },

    computed: {
        ...mapGetters(["user"]),
        ...mapGetters(["userinfo"]),
    },

    //生命周期--创建完成
    created() {

    },

    //生命周期--挂载完成
    mounted() {
    },

    activated() {
      this.$refs.multipleTable.clearSelection();
      this.itOrder=this.params.itOrder
      console.log("itOrder是"+this.itOrder)
      if(this.itOrder){
        this.itOrder.split(',').forEach(index => {
          console.log("ZZZZZZZZZZZ"+index)
          this.$refs.multipleTable.toggleRowSelection(this.listData[index-1]);
        });
      }
    },
    //方法调用
    methods: {
      //复选框改变时获取所选中的数据
      handleSelectionChange(val) {
        console.log("点击选择框后"+JSON.stringify(val))
        var lastType=""
        if(val.length>0){
          lastType=val[val.length-1].model
        }
        this.multipleSelection = val;
        var zizhuType=false
        var feiZizhuType=false
        var zizhuValue=""
        var feiZizhuValue=""
          for (let i = 0; i < this.multipleSelection.length; i++) {
            if(this.multipleSelection[i].model=="自主项目"){
              zizhuType=true
              // if(zizhuValue==""){
              //   zizhuValue=this.multipleSelection[i].typetomodel
              // }else if(zizhuValue.includes(this.multipleSelection[i].typetomodel)){
              //   zizhuValue=zizhuValue+","+this.multipleSelection[i].typetomodel
              // }
            }
            if(this.multipleSelection[i].model=="非自主项目"){
              feiZizhuType=true
              // feiZizhuValue="非自主项目"
            }
          }
          if(zizhuType==true&&feiZizhuType==true){
            // if(lastType=="非自主项目"){
            //   this.multipleSelection.forEach(row => {
            //     if(row.model=="自主项目"){
            //       this.multipleSelection.remove(row);
            //     }
            //   });
            // }else if(lastType=="自主项目"){
            //   this.multipleSelection.forEach(row => {
            //     if(row.model=="非自主项目"){
            //       this.multipleSelection.remove(row);
            //     }
            //   });
            // }
            console.log("修改后的"+JSON.stringify(this.multipleSelection))
            // if (this.multipleSelection) {
            //   this.multipleSelection.forEach(row => {
            //     console.log("ZZZZZZZZZZZ"+JSON.stringify(row))
            //     this.$refs.multipleTable.toggleRowSelection(row);
            //   });
            // } else {
            //   console.log("XXXXXXXXXXXX")
            //   this.$refs.multipleTable.clearSelection();
            // }
            Notify('自主项目和非自主项目不可同时选择');
          }
        },
      onSubmit() {

        var zizhuType=false
        var feiZizhuType=false
        var zizhuValue=""
        var feiZizhuValue=""
        var number=0
        for (let i = 0; i < this.multipleSelection.length; i++) {
          if(this.multipleSelection[i].model=="自主项目"){
            zizhuType=true
            if(zizhuValue==""){
              zizhuValue=this.multipleSelection[i].typetomodel
            }else if(!zizhuValue.includes(this.multipleSelection[i].typetomodel)){
                zizhuValue=zizhuValue+","+this.multipleSelection[i].typetomodel
            }
          }
          if(this.multipleSelection[i].model=="非自主项目"){
            feiZizhuType=true
            feiZizhuValue="非自主项目"
          }
          number=number+Number(this.multipleSelection[i].number)
        }
        if(zizhuType==true&&feiZizhuType==true){
          Notify('自主项目和非自主项目不可同时选择');
          return
        }else if(zizhuType==false&&feiZizhuType==false){
          Notify('自主项目和非自主项目必须选择一项');
          return
        }
        var value=""
        var iszizhu="0"
        if(zizhuValue!=""){
          value=zizhuValue
          iszizhu="1"
        }else if(feiZizhuValue!=""){
          value=feiZizhuValue
          iszizhu="0"
        }
        console.log("传送的数据是"+value+"XXX"+number)
        localStorage.setItem('itListNumber', JSON.stringify(number))
        localStorage.setItem('itListValue', JSON.stringify(value))
        localStorage.setItem('itListIsZiZhu', JSON.stringify(iszizhu))
        this.$router.back(-1)
      },
    },
};
</script>

<style scoped>
/* @import url();*/
</style>